
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JButton;
import javax.swing.JFrame;

public class Controller extends JFrame implements ActionListener, KeyListener {

	JButton north_btn;
	JButton east_btn;
	JButton south_btn;
	JButton west_btn;
	
	int directionCommand = Direction.NODIRECTION;
	
	public Controller() {
		
		this.setSize(250, 250);
	    this.setLocation(300,200);
	    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    
	    north_btn = new JButton("NORTH");
	    east_btn = new JButton("EAST");
	    south_btn = new JButton("SOUTH");
	    west_btn = new JButton("WEST");
	    
	    north_btn.setActionCommand(String.valueOf(Direction.NORTH));
	    east_btn.setActionCommand(String.valueOf(Direction.EAST));
	    south_btn.setActionCommand(String.valueOf(Direction.SOUTH));
	    west_btn.setActionCommand(String.valueOf(Direction.WEST));
	    
	    north_btn.addActionListener(this);
	    east_btn.addActionListener(this);
	    south_btn.addActionListener(this);
	    west_btn.addActionListener(this);
	    
	    this.addKeyListener(this);
	    
	    //this.getContentPane().add(BorderLayout.CENTER, new JTextArea(10, 40));
	    Container content = this.getContentPane();
	    GridLayout gridLayout = new GridLayout(0,3);
	    this.setLayout(gridLayout);
	    
	    content.add(new JButton());
	    content.add(north_btn);
	    content.add(new JButton());
	    content.add(west_btn);
	    content.add(new JButton());
	    content.add(east_btn);
	    content.add(new JButton());
	    content.add(south_btn);
	    content.add(new JButton());
	    
	    this.setTitle("Odin Controller");
	    this.setVisible(true);
	}
	
	public int getDirectionCommand() {
		return directionCommand;
	}
	
	public void resetDirectionCommand() {
		directionCommand = Direction.NODIRECTION;
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		directionCommand = Integer.parseInt(e.getActionCommand());
		System.out.println(String.valueOf(directionCommand));
	}
	
	@Override
	public void keyPressed(KeyEvent event) {
		
	}

	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub
		
		/*
		int keyCode = e.getKeyCode();
	    
	    if (keyCode == KeyEvent.VK_LEFT)
	    	directionCommand = Direction.WEST;
	    else if (keyCode == KeyEvent.VK_RIGHT)
	    	directionCommand = Direction.EAST;
	    else if (keyCode == KeyEvent.VK_UP)
	    	directionCommand = Direction.NORTH;
	    else if (keyCode == KeyEvent.VK_DOWN)
	    	directionCommand = Direction.SOUTH;
	    
	    System.out.println(String.valueOf(directionCommand));
	    */
		
	}

	@Override
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}
}
